home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2005 July
/
CHIP_CD_2005-07.iso
/
software
/
att
/
attsetup.exe
/
Smart Shaders
/
Sharpen.pss
< prev
Wrap
Text File
|
2004-01-16
|
3KB
|
100 lines
shader convolutionPixelShader=
"!!ARBfp1.0
# This is a general purpose 3x3 convolution filter. Unused instructions
# and constants will get culled out by the driver so no need to remove them here.
PARAM texCoord00 = program.local[0];
PARAM texCoord01 = program.local[1];
PARAM texCoord02 = program.local[2];
PARAM texCoord10 = program.local[3];
PARAM texCoord12 = program.local[5];
PARAM texCoord20 = program.local[6];
PARAM texCoord21 = program.local[7];
PARAM texCoord22 = program.local[8];
# These constants are setup to do a sharpen filter.
PARAM const00 = {-1.0, -1.0, -1.0, 0.0};
PARAM const01 = {-1.0, -1.0, -1.0, 0.0};
PARAM const02 = {-1.0, -1.0, -1.0, 0.0};
PARAM const10 = {-1.0, -1.0, -1.0, 0.0};
PARAM const11 = {9.0, 9.0, 9.0, 0.0};
PARAM const12 = {-1.0, -1.0, -1.0, 0.0};
PARAM const20 = {-1.0, -1.0, -1.0, 0.0};
PARAM const21 = {-1.0, -1.0, -1.0, 0.0};
PARAM const22 = {-1.0, -1.0, -1.0, 0.0};
TEMP finalPixel;
TEMP coord00;
TEMP coord01;
TEMP coord02;
TEMP coord10;
TEMP coord11;
TEMP coord12;
TEMP coord20;
TEMP coord21;
TEMP coord22;
OUTPUT oColor = result.color;
# Generate all the texture coordinates for the 9 texture lookups
ADD coord00, texCoord00, fragment.texcoord[0];
ADD coord01, texCoord01, fragment.texcoord[0];
ADD coord02, texCoord02, fragment.texcoord[0];
ADD coord10, texCoord10, fragment.texcoord[0];
ADD coord12, texCoord12, fragment.texcoord[0];
ADD coord20, texCoord20, fragment.texcoord[0];
ADD coord21, texCoord21, fragment.texcoord[0];
ADD coord22, texCoord22, fragment.texcoord[0];
# Do the texture lookups for the 3x3 kernel
TEX coord00, coord00, texture[0], 2D;
TEX coord01, coord01, texture[0], 2D;
TEX coord02, coord02, texture[0], 2D;
TEX coord10, coord10, texture[0], 2D;
TEX coord11, fragment.texcoord[0], texture[0], 2D;
TEX coord12, coord12, texture[0], 2D;
TEX coord20, coord20, texture[0], 2D;
TEX coord21, coord21, texture[0], 2D;
TEX coord22, coord22, texture[0], 2D;
# Multiply all texture lookups by their weights and sum them up
MUL finalPixel, coord00, const00;
MAD finalPixel, coord10, const10, finalPixel;
MAD finalPixel, coord20, const20, finalPixel;
MAD finalPixel, coord01, const01, finalPixel;
MAD finalPixel, coord11, const11, finalPixel;
MAD finalPixel, coord21, const21, finalPixel;
MAD finalPixel, coord02, const02, finalPixel;
MAD finalPixel, coord12, const12, finalPixel;
MAD oColor, coord22, const22, finalPixel;
END";
shader copyPixelShader =
"!!ARBfp1.0
OUTPUT oColor = result.color;
TEMP pixel;
TEX pixel, fragment.texcoord[0], texture[0], 2D;
MOV oColor, pixel;
END";
surface temp = allocsurf(width, height);
convolutionPixelShader.constant[0] = {-ds_dx, -dt_dy, 0, 0};
convolutionPixelShader.constant[1] = {0, -dt_dy, 0, 0};
convolutionPixelShader.constant[2] = {ds_dx, -dt_dy, 0, 0};
convolutionPixelShader.constant[3] = {-ds_dx, 0, 0, 0};
convolutionPixelShader.constant[4] = {ds_dx, 0, 0, 0};
convolutionPixelShader.constant[5] = {-ds_dx, dt_dy, 0, 0};
convolutionPixelShader.constant[6] = {0, dt_dy, 0, 0};
convolutionPixelShader.constant[7] = {ds_dx, dt_dy, 0, 0};
texture[0].source = backbuffer;
destination temp;
apply convolutionPixelShader;
texture[0].source = temp;
destination backbuffer;
apply copyPixelShader;